AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include('shared.lua')
local Ground = 1 + 0 + 2 + 8 + 32

function ENT:Initialize()
	self.Entity:SetModel("models/props_c17/substation_stripebox01a.mdl")
	self.Entity:PhysicsInit( SOLID_VPHYSICS )
	self.Entity:SetMoveType( MOVETYPE_VPHYSICS )
	self.Entity:SetSolid( SOLID_VPHYSICS )
	local phys = self.Entity:GetPhysicsObject()
	self.update = CurTime() +  1
	self.done = false
	if (phys:IsValid()) then
		phys:Wake()
	end
end

function ENT:SpawnFunction( ply, tr )
	if ( !tr.Hit ) then return end
	local SpawnPos = tr.HitPos + tr.HitNormal * 36
	local ent = ents.Create( "shield_extender" )
	ent:SetPos( SpawnPos )
	ent:Spawn()
	ent:Activate()
	return ent
end

function ENT:OnRemove()
	if self.done then
		if self.core:IsValid() then
			self.core.maxshield = self.core.maxshield -5000
			if (self.core.shield > self.core.maxshield) then
				self.core.shield = self.core.maxshield
			end
		end
	end
end

function ENT:Think()
	if self.core then
		if  (self.core:IsValid()) then	
			if self.done then
				self.Entity:NextThink( CurTime() + 30 )
			else
				self.core.maxshield = self.core.maxshield +5000
				self.done = true
			end
		else
			self.core = nil
		end
	else
		self.core = getshipcore(self.Entity)
		Msg (tostring(self.core) .. "\n")
		if not self.core then
			self.Entity:NextThink( CurTime() + 5 )
			return true
		end
	end
	self.Entity:NextThink(CurTime() + 1)
	return true
end

function ENT:OnTakeDamage(info)
	Shieldhit(info,self.Entity)
end
